package com.mdlib.helper.module.send.order.fragments;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.ljlib.core.util.BitmapUtil;
import com.ljlib.core.util.EmptyUtils;
import com.ljlib.core.util.LogUtil;
import com.ljlib.core.util.common.TimeUtils;
import com.ljlib.help.R;
import com.mdlib.helper.api.DataManager;
import com.mdlib.helper.api.MDUploadPic;
import com.mdlib.helper.api.network.RxHelper;
import com.mdlib.helper.api.network.RxSubscribe;
import com.mdlib.helper.base.BaseTitleFragment;
import com.mdlib.helper.common.MDConstant;
import com.mdlib.helper.event.AddressEvent;
import com.mdlib.helper.event.ImageID;
import com.mdlib.helper.event.MoneyEvent;
import com.mdlib.helper.event.PhoneEvent;
import com.mdlib.helper.event.TimeEvent;
import com.mdlib.helper.event.VoucherEvent;
import com.mdlib.helper.model.AppModel;
import com.mdlib.helper.model.entity.OrderIdInfo;
import com.mdlib.helper.model.entity.ServiceMoney;
import com.mdlib.helper.model.entity.VoucherEntity;
import com.mdlib.helper.module.location.AddressEntity;
import com.mdlib.helper.module.location.LocationHelper;
import com.mdlib.helper.module.location.LocationView;
import com.mdlib.helper.module.location.MapActivity;
import com.mdlib.helper.ui.UIHelper;
import com.mdlib.helper.ui.adapter.MinnOrTakeAdapter;
import com.mdlib.helper.utils.RecyclerItemClickListener;
import com.mdlib.helper.utils.ToastUtil;
import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.model.PhotoInfo;
import me.leefeng.promptlibrary.PromptButton;
import me.leefeng.promptlibrary.PromptButtonListener;
import me.leefeng.promptlibrary.PromptDialog;

/**
 * 作者：HQY on 16/11/19 10:48
 * 邮箱：hqy_xz@126.com
 * 代买和代送取
 */

public class MinnetonkaFragment extends BaseTitleFragment implements LocationView {

    private final int REQUEST_CODE_GALLERY = 1001;
    @Bind(R.id.rl_minnetonka_describe)
    RelativeLayout mRlMinnetonkaDescribe;
    @Bind(R.id.iv_shopping_address)
    ImageView mIvShoppingAddress;
    @Bind(R.id.iv_minnetoka_back_one)
    ImageView mIvMinnetokaBackOne;
    @Bind(R.id.rl_shopping_address)
    RelativeLayout mRlShoppingAddress;
    @Bind(R.id.iv_delivery_address)
    ImageView mIvDeliveryAddress;
    @Bind(R.id.iv_minnetoka_back_two)
    ImageView mIvMinnetokaBackTwo;
    @Bind(R.id.rl_delivery_address)
    RelativeLayout mRlDeliveryAddress;
    @Bind(R.id.iv_success_time)
    ImageView mIvSuccessTime;
    @Bind(R.id.iv_minnetoka_back_three)
    ImageView mIvMinnetokaBackThree;
    @Bind(R.id.tv_minnetonka_time)
    TextView mTvMinnetonkaTime;
    @Bind(R.id.rl_success_time)
    RelativeLayout mRlSuccessTime;
    @Bind(R.id.iv_harves_phone)
    ImageView mIvHarvesPhone;
    @Bind(R.id.iv_minnetoka_back_four)
    ImageView mIvMinnetokaBackFour;
    @Bind(R.id.tv_minnetonka_phone)
    TextView mTvMinnetonkaPhone;
    @Bind(R.id.rl_minnetonka_phone)
    RelativeLayout mRlMinnetonkaPhone;
    @Bind(R.id.iv_service_money)
    ImageView mIvServiceMoney;
    @Bind(R.id.iv_minnetoka_back_five)
    ImageView mIvMinnetokaBackFive;
    @Bind(R.id.tv_minnetonka_money)
    TextView mTvMinnetonkaMoney;
    @Bind(R.id.rl_service_money)
    RelativeLayout mRlServiceMoney;
    @Bind(R.id.iv_minnetonka_voucher)
    ImageView mIvMinnetonkaVoucher;
    @Bind(R.id.iv_minnetoka_back_six)
    ImageView mIvMinnetokaBackSix;
    @Bind(R.id.tv_minnetonka_voucher)
    TextView mTvMinnetonkaVoucher;
    @Bind(R.id.rl_minnetonka_voucher)
    RelativeLayout mRlMinnetonkaVoucher;
    @Bind(R.id.tv_pay_money)
    TextView mTvPayMoney;
    @Bind(R.id.tv_pay_submit)
    TextView mTvPaySubmit;

    @Bind(R.id.tv_send_phone)
    TextView mTvSendPhone;
    @Bind(R.id.rl_send_phone)
    RelativeLayout mRlSendPhone;
    @Bind(R.id.et_describe)
    EditText mEtDescribe;
    @Bind(R.id.iv_send_phone)
    ImageView mIvSendPhone;
    @Bind(R.id.iv_send_back_senven)
    ImageView mIvSendBackSenven;
    @Bind(R.id.iv_order_add)
    ImageView mIvOrderAdd;
    @Bind(R.id.rv_order_goods_pic)
    RecyclerView mRvOrderGoodsPic;

    @Bind(R.id.tv_post_addr)
    TextView mTvPostAddr;
    @Bind(R.id.iv_order_add_twp)
    ImageView mIvOrderAddTwp;
    @Bind(R.id.tv_get_addr)
    TextView mTvGetAddr;

    private MinnOrTakeAdapter minnOrTakeAdapter;
    private List<PhotoInfo> photoInfoList = new ArrayList<>();

    private String type;

    private ServiceMoney serviceMoney;
    private long timestamp = 0;
    private String time;

    private String remark;
    private String getAddr;
    private String postAddr;
    private String postPhone;
    private String getPhone;
    private String serviceMoneys;
    private String voucher;
    private String vouchers = "";

    private String oneLat = "0.0";
    private String oneLong = "0.0";

    private String twoLat = "0.0";
    private String twoLong = "0.0";

    private String lats = "0.0";
    private String longs = "0.0";
    private int num = 0;
    private int picNum = 0;


    private LocationHelper mLocationHelper;


    public static MinnetonkaFragment newInstance(String type) {
        MinnetonkaFragment fragment = new MinnetonkaFragment();
        Bundle bundle = new Bundle();
        bundle.putString(UIHelper.TYPE, type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        Bundle bundle = getArguments();
        if (bundle != null) {
            type = bundle.getString(UIHelper.TYPE);
            LogUtil.e(type);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        if (mLocationHelper != null) {
            mLocationHelper.onSart();
        }

    }

    @Override
    public void onStop() {
        super.onStop();
        if (mLocationHelper != null) {
            mLocationHelper.onStop();
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);

        if (mLocationHelper != null) {
            mLocationHelper.onDestory();
        }
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_minnetonka;
    }

    @Override
    protected void initView(View rootView) {
        super.initView(rootView);
        if (type.equals(UIHelper.MONNETONKA)) {
            setTitle(R.string.send_home_minnetonka, R.color.white)
                    .setTitleBgColor(R.color.generic_view_bg)
                    .setImgLeftListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            removeFragment();
                        }
                    });
            lats = AppModel.getInstance().getAppLocationEntity().getLats();
            longs = AppModel.getInstance().getAppLocationEntity().getLongs();
            mRlSendPhone.setVisibility(View.GONE);
            mEtDescribe.setHint(getActivity().getResources().getString(R.string.minnetonka_et_hint_one));
            mTvGetAddr.setText(getActivity().getResources().getString(R.string.minnetonka_shopping_address));
            mTvPostAddr.setText(AppModel.getInstance().getAppInitEntity().getAddress());
            getServiceMoney();
        } else if (type.equals(UIHelper.TAKE)) {
            setTitle(R.string.send_home_take, R.color.white)
                    .setTitleBgColor(R.color.generic_view_bg)
                    .setImgLeftListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            removeFragment();
                        }
                    });
            mEtDescribe.setHint(getActivity().getResources().getString(R.string.minnetonka_et_hint_two));
            mRlSendPhone.setVisibility(View.VISIBLE);
            mTvGetAddr.setText(getActivity().getResources().getString(R.string.take_delivery_address));

            mLocationHelper = new LocationHelper(getActivity(), this);
            getTakeServiceMoney();
        }
        init();

    }

    private void init() {
        if (EmptyUtils.isNotEmpty(AppModel.getInstance().getAppInitEntity())) {
            mTvMinnetonkaPhone.setText(AppModel.getInstance().getAppInitEntity().getPhone());
            mTvSendPhone.setText(AppModel.getInstance().getAppInitEntity().getPhone());
        }
        minnOrTakeAdapter = new MinnOrTakeAdapter(photoInfoList, getActivity());
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRvOrderGoodsPic.setLayoutManager(layoutManager);
        mRvOrderGoodsPic.setAdapter(minnOrTakeAdapter);
        mRvOrderGoodsPic.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                int number = minnOrTakeAdapter.removeData(position);
                picNum--;
                if (number <= 0) {
                    mIvOrderAdd.setVisibility(View.VISIBLE);
                    mRvOrderGoodsPic.setVisibility(View.GONE);
                    mIvOrderAddTwp.setVisibility(View.GONE);
                } else if (number > 0 && number < 3) {
                    mIvOrderAddTwp.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onLongClick(View view, int posotion) {

            }
        }));
        cancle = new PromptButton("取消", null);

        promptDialog = new PromptDialog(getActivity());
        cancle.setTextColor(Color.parseColor("#0076ff"));
    }

    PromptButton cancle;

    PromptDialog promptDialog;

    @OnClick({R.id.rl_shopping_address, R.id.iv_order_add_twp, R.id.rl_delivery_address, R.id.rl_success_time, R.id.rl_minnetonka_phone, R.id.rl_service_money, R.id.rl_minnetonka_voucher, R.id.tv_pay_submit, R.id.rl_send_phone, R.id.iv_order_add})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_order_add:
                //带配置
                final FunctionConfig config = new FunctionConfig.Builder()
                        .setEnableCamera(true)
                        .setMutiSelectMaxSize(3)
                        .build();


                promptDialog.showAlertSheet("", true, cancle,
                        new PromptButton("相册", new PromptButtonListener() {
                            @Override
                            public void onClick(PromptButton promptButton) {
                                GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, config, mOnHanlderResultCallback);
                            }
                        }), new PromptButton("拍照", new PromptButtonListener() {
                            @Override
                            public void onClick(PromptButton promptButton) {
                                GalleryFinal.openCamera(REQUEST_CODE_GALLERY, config, mOnHanlderResultCallback);

                            }
                        }));

                break;
            case R.id.iv_order_add_twp:
                num = 3 - picNum;
                if (num > 0) {
                    final FunctionConfig configs = new FunctionConfig.Builder().setMutiSelectMaxSize(num)
                            .setEnableCamera(true)
                            .build();
                    PromptButton cancle = new PromptButton("取消", null);
                    cancle.setTextColor(Color.parseColor("#0076ff"));
                    PromptDialog promptDialog = new PromptDialog(getActivity());
                    promptDialog.showAlertSheet("", true, cancle,
                            new PromptButton("相册", new PromptButtonListener() {
                                @Override
                                public void onClick(PromptButton promptButton) {
                                    GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, configs, mOnHanlderResultCallback);
                                }
                            }), new PromptButton("拍照", new PromptButtonListener() {
                                @Override
                                public void onClick(PromptButton promptButton) {
                                    GalleryFinal.openCamera(REQUEST_CODE_GALLERY, configs, mOnHanlderResultCallback);

                                }
                            }));
                    //带配置


                } else {
                    ToastUtil.showToast("已到最大图片数量!");
                }
                break;
            case R.id.rl_shopping_address:
                if (type.equals(UIHelper.MONNETONKA)) {
                    UIHelper.showMapPage(getActivity(), UIHelper.MAP_TYPE_ONE, UIHelper.MONNETONKA);
                } else {
                    UIHelper.showMapPage(getActivity(), UIHelper.MAP_TYPE_ONE, UIHelper.TAKE);
                }
                break;
            case R.id.rl_delivery_address:
                if (type.equals(UIHelper.MONNETONKA)) {
                    UIHelper.showAddress(getActivity(), UIHelper.ADDRESS_TYPE_ONE);
                } else {
                    UIHelper.showMapPage(getActivity(), UIHelper.MAP_TYPE_TWO, UIHelper.TAKE);
                }
                break;
            case R.id.rl_success_time:
                UIHelper.showSuccessTime(getActivity());
                break;
            case R.id.rl_minnetonka_phone:
                UIHelper.showModifyPHone(getActivity(), mTvMinnetonkaPhone.getText().toString(), UIHelper.MONNETONKA);
                break;
            case R.id.rl_send_phone:
                UIHelper.showModifyPHone(getActivity(), mTvSendPhone.getText().toString(), UIHelper.TAKE);
                break;
            case R.id.rl_service_money:
                if (!type.equals(UIHelper.MONNETONKA)) {
                    //serviceMoney=new ServiceMoney();
                    serviceMoney.setMinServiceMoney(serviceMoney.getServiceMoney());
                    serviceMoney.setMxServiceMoney(Double.parseDouble("1000"));
                    serviceMoney.setServiceMoneyStep(Double.parseDouble("1"));
                }
                UIHelper.showServiceMoney(getActivity(), serviceMoney);
                break;
            case R.id.rl_minnetonka_voucher:
                getVoucher();
                break;
            case R.id.tv_pay_submit:
                remark = mEtDescribe.getText().toString();
                postAddr = mTvPostAddr.getText().toString();
                postPhone = mTvSendPhone.getText().toString();
                getPhone = mTvMinnetonkaPhone.getText().toString();
                voucher = mTvMinnetonkaVoucher.getText().toString();
                if (EmptyUtils.isEmpty(remark)) {
                    ToastUtil.showToast(getActivity().getResources().getString(R.string.generic_et_not_empty));
                    return;
                }
                if (EmptyUtils.isEmpty(oneLat)) {
                    ToastUtil.showToast(getActivity().getResources().getString(R.string.generic_et_address_not_empty));
                    return;
                }
                if (EmptyUtils.isEmpty(getPhone)) {
                    ToastUtil.showToast(getActivity().getResources().getString(R.string.generic_et_phone_not_empty));
                    return;
                }
                LogUtil.e(mTvGetAddr.getText().toString());
                if (mTvGetAddr.getText().toString().equals("请选择取货地址")) {
                    ToastUtil.showToast("取货地址不能为空");
                    return;
                }
                if (postAddr.equals("请选择送货地址")) {
                    ToastUtil.showToast("送货地址不能为空");
                    return;
                }
//                if (!EmptyUtils.isEmpty(voucher)) {
//                    vouchers = voucher.substring(1, voucher.length() - 3);
//                }
                String money = mTvMinnetonkaMoney.getText().toString();
                if (money.length() > 1) {
                    serviceMoneys = money.substring(1, money.length());
                } else {
                    serviceMoneys = money;
                }
                List<String> imgList = new ArrayList<>();
                BitmapUtil bitmapUtil = new BitmapUtil();
                if (!EmptyUtils.isEmpty(minnOrTakeAdapter.getList())) {
                    for (int i = 0; i < minnOrTakeAdapter.getList().size(); i++) {
                        String urlImages = bitmapUtil.prepareFile(minnOrTakeAdapter.getList().get(i).getPhotoPath());
                        imgList.add(urlImages);
                    }
                    MDUploadPic.uploadPic(imgList, getActivity(), "3");
                } else {
                    mRequest("");
                }

                break;
        }
    }

    private void mRequest(String imgId) {

        getAddr = mTvGetAddr.getText().toString().substring(8);
        if (type.equals(UIHelper.MONNETONKA)) {
            sendOrder(remark, getAddr, postAddr, timestamp + "", getPhone, serviceMoneys,
                    imgId, lats, longs, vouchers);
        } else if (type.equals(UIHelper.TAKE)) {
            if (EmptyUtils.isEmpty(postPhone)) {
                ToastUtil.showToast(getActivity().getResources().getString(R.string.generic_et_phone_not_empty));
                return;
            }
            if (EmptyUtils.isEmpty(twoLat)) {
                ToastUtil.showToast(getActivity().getResources().getString(R.string.generic_et_address_not_empty));
                return;
            }
            postAddr = postAddr.substring(5);
            sendTake(remark, getAddr, postAddr, timestamp + "", getPhone, serviceMoneys, imgId,
                    lats, longs, vouchers, postPhone, oneLat, oneLong, twoLat, twoLong);
        }
    }

    /**
     * 代买
     *
     * @param remark
     * @param postAddr
     * @param getAddr
     * @param hopeTime
     * @param getPhone
     * @param money
     * @param picId
     * @param lat
     * @param length
     * @param couponId
     */
    private void sendOrder(String remark, String postAddr, String getAddr, String hopeTime,
                           String getPhone, String money, String picId,
                           String lat, String length, String couponId) {
        addSubscribe(DataManager.getInstance().getUserApi()
                .sendMinnetoka(remark, postAddr, getAddr, hopeTime, getPhone, MDConstant.PLATFORM, money, "2", picId, lat, length, couponId)
                .compose(RxHelper.<OrderIdInfo>defaultHandleResult())
                .subscribe(new RxSubscribe<OrderIdInfo>() {
                    @Override
                    protected void onSucc(OrderIdInfo orderIdInfo) {
                        UIHelper.showPayOrder(getActivity(), orderIdInfo);
                    }

                    @Override
                    protected void onFail(String msg) {
                        ToastUtil.showToast(msg);
                    }
                }));

    }

    /**
     * 代送取
     *
     * @param remark
     * @param postAddr
     * @param getAddr
     * @param hopeTime
     * @param getPhone
     * @param money
     * @param picId
     * @param lat
     * @param length
     * @param couponId
     * @param postPhone
     * @param postLat
     * @param postLong
     * @param getLat
     * @param getLong
     */
    private void sendTake(String remark, String postAddr, String getAddr, String hopeTime,
                          String getPhone, String money, String picId,
                          String lat, String length, String couponId, String postPhone, String postLat
            , String postLong, String getLat, String getLong) {
        startLoadingDialog(true);
        addSubscribe(DataManager.getInstance().getUserApi()
                .sendTake(remark, postAddr, getAddr, hopeTime, getPhone, MDConstant.PLATFORM, money, "3",
                        lat, length, picId, couponId, postPhone, postLat, postLong, getLat, getLong)
                .compose(RxHelper.<OrderIdInfo>defaultHandleResult())
                .subscribe(new RxSubscribe<OrderIdInfo>() {
                    @Override
                    protected void onSucc(OrderIdInfo orderIdInfo) {
                        stopLoadingDialog();
                        UIHelper.showPayOrder(getActivity(), orderIdInfo);
                    }

                    @Override
                    protected void onFail(String msg) {
                        stopLoadingDialog();
                        ToastUtil.showToast(msg);
                    }
                }));

    }

    private GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback = new GalleryFinal.OnHanlderResultCallback() {
        @Override
        public void onHanlderSuccess(int reqeustCode, final List<PhotoInfo> resultList) {
            picNum = resultList.size() + picNum;
            if (picNum < 3) {
                mIvOrderAddTwp.setVisibility(View.VISIBLE);
            } else {
                mIvOrderAddTwp.setVisibility(View.GONE);
            }
            getOrderPicList(resultList);
        }

        @Override
        public void onHanlderFailure(int requestCode, String errorMsg) {
            ToastUtil.showToast(errorMsg);
        }
    };

    private void getOrderPicList(final List<PhotoInfo> list) {
        if (list.size() > 0) {
            mIvOrderAdd.setVisibility(View.GONE);
            mRvOrderGoodsPic.setVisibility(View.VISIBLE);
            photoInfoList = list;
            minnOrTakeAdapter.addItem(list);
        } else {
            mIvOrderAdd.setVisibility(View.VISIBLE);
            mRvOrderGoodsPic.setVisibility(View.GONE);
        }
    }

    private void getTakeServiceMoney() {
        addSubscribe(DataManager.getInstance().getUserApi()
                .getTakeServiceMoney(oneLat, oneLong, twoLat, twoLong)
                .compose(RxHelper.<ServiceMoney>defaultHandleResult())
                .subscribe(new RxSubscribe<ServiceMoney>() {
                    @Override
                    protected void onSucc(ServiceMoney serviceMoneys) {
                        serviceMoney = serviceMoneys;
                        mTvMinnetonkaMoney.setText("￥" + serviceMoney.getServiceMoney());
                        //mRlServiceMoney.setEnabled(false);
                        mTvPayMoney.setText("￥" + serviceMoney.getServiceMoney());
                    }

                    @Override
                    protected void onFail(String msg) {

                    }
                }));
    }

    private void getServiceMoney() {

        addSubscribe(DataManager.getInstance().getUserApi()
                .getServiceMoney()
                .compose(RxHelper.<ServiceMoney>defaultHandleResult())
                .subscribe(new RxSubscribe<ServiceMoney>() {
                    @Override
                    protected void onSucc(ServiceMoney serviceInfo) {
                        serviceMoney = serviceInfo;
                        mTvMinnetonkaMoney.setText("￥" + serviceMoney.getMinServiceMoney());
                        mTvPayMoney.setText("￥" + serviceMoney.getMinServiceMoney());
                    }

                    @Override
                    protected void onFail(String msg) {
                        ToastUtil.showToast(msg);
                    }
                }));
    }

    private void getVoucher() {
        addSubscribe(DataManager.getInstance().getUserApi()
                .getMyVoucher()
                .compose(RxHelper.<ArrayList<VoucherEntity>>defaultHandleResult())
                .subscribe(new RxSubscribe<ArrayList<VoucherEntity>>() {
                    @Override
                    protected void onSucc(ArrayList<VoucherEntity> voucherEntities) {
                        UIHelper.showDialogVoucher(getActivity(), voucherEntities);
                    }

                    @Override
                    protected void onFail(String msg) {
                        ToastUtil.showToast(msg);
                    }
                })
        );
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != Activity.RESULT_OK) {
            return;
        }

        if (requestCode == MapActivity.REQUEST_ADDRESS_CODE) {
            AddressEntity addressEntity = (AddressEntity) data.getSerializableExtra(MapActivity.EXTRA_ADDRESS_MAP);
            String mapType = data.getStringExtra(UIHelper.MAP_TYPE);
            if (mapType.equals(UIHelper.MAP_TYPE_ONE)) {
                String address;
                if (type.equals(UIHelper.MONNETONKA)) {
                    address = getActivity().getResources().getString(R.string.minnetonka_shopp_address, addressEntity.getDetailAddress());
                } else {
                    address = getActivity().getResources().getString(R.string.take_get_address, addressEntity.getDetailAddress());
                }
                mTvGetAddr.setText(address);
                oneLat = String.valueOf(addressEntity.getLatitude());
                oneLong = String.valueOf(addressEntity.getLongitude());
            } else if (mapType.equals(UIHelper.MAP_TYPE_TWO)) {
                mTvPostAddr.setText(getActivity().getResources().getString(R.string.minnetonka_send_address, addressEntity.getDetailAddress()));
                twoLat = String.valueOf(addressEntity.getLatitude());
                twoLong = String.valueOf(addressEntity.getLongitude());
                LogUtil.e("坐标: " + twoLat + "   " + twoLong);
                getTakeServiceMoney();
            }

        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MoneyEvent moneyEvent) {
        mTvMinnetonkaMoney.setText(moneyEvent.getMoney());
        mTvPayMoney.setText(moneyEvent.getMoney());
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(VoucherEvent voucherEvent) {
        vouchers = voucherEvent.getVoucherEntity().getId() + "";
        mTvMinnetonkaVoucher.setText("￥" + voucherEvent.getVoucherEntity().getValue() + "代金券");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(PhoneEvent phoneEvent) {
        if (phoneEvent.getType().equals(UIHelper.MONNETONKA)) {
            mTvMinnetonkaPhone.setText(phoneEvent.getPhone());
        } else if (phoneEvent.getType().equals(UIHelper.TAKE)) {
            mTvSendPhone.setText(phoneEvent.getPhone());
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ImageID id) {
        if (type.equals(UIHelper.MONNETONKA)) {
            mRequest(id.getIdList().toString());
        } else if (type.equals(UIHelper.TAKE)) {
            mRequest(id.getIdList().toString());
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(AddressEvent addressEvent) {
        mTvPostAddr.setText(addressEvent.getAddresName());
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(TimeEvent timeEvent) {
        time = TimeUtils.getCurTimeString(TimeUtils.SUCCESS_YEAR) + "." + timeEvent.getMonth() + " " + timeEvent.getHour();
        timestamp = TimeUtils.string2Milliseconds(time, TimeUtils.SUCCESS_MONTH) / 1000;
        if (timestamp == 0) {
            mTvMinnetonkaTime.setText("尽快");
        } else {
            mTvMinnetonkaTime.setText(time);
        }
    }


    @Override
    public void showLocation(AMapLocation location) {
        if (location != null) {
            Logger.e("地址定位" + location.toString() + location.getDistrict());
            lats = String.valueOf(location.getLatitude());
            longs = String.valueOf(location.getLongitude());
        }

    }

}
